/****************************************************
 * 
 * home soft 版权所有.
 * 
 *****************************************************/
package com.homesoft.runtime.metadata.modle;

import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.thoughtworks.xstream.annotations.XStreamOmitField;

/**
 * @author lihg
 * @data 2012-9-15
 */
public abstract class  NotifierList<K, V> extends KeyedCollection<K,V> implements INotifierList<V> {

	private static final long serialVersionUID = 1L;
	@XStreamOmitField 
	private IOwnerAware _owner;
	@XStreamOmitField 
	private String _memberName;

	public NotifierList(IOwnerAware owner, String memberName) {
		this._owner = owner;
		this._memberName = memberName;
	}

	@Override
	public IOwnerAware getOwner() {
		return _owner;
	}

	@Override
	public void setOwner(IOwnerAware owner) {
		this._owner = owner;
	}

	@Override
	public String getMemberName() {
		return this._memberName;
	}

	@Override
	public void setMemberName(String memberName) {
		this._memberName = memberName;
	}

	@Override
	public String getObjectPath() {
		StringBuilder builder = new StringBuilder(200);
        IOwnerAware ownerAware = this._owner;
        if (ownerAware != null)
        {
            builder.append(ownerAware.getObjectPath());
        }

        INotifierList notifierList = (INotifierList)ownerAware ;
        if (notifierList != null)
        {

            //if (notifierList is IMetadataList && this is IMetadataObject)
            //{
            //    //如果是MetadataList使用Name进行索引
            //    string name = ((IMetadataObject)this).Name;
            //    builder.Append("[\"").Append(name).Append("\"]");
            //}
            //else
            //{
        	//TODO_HG:这个地方取当前的这个list是owner里面是第几个。
        	//for (int i = 0 ,len = notifierList.size();i++) {
        		
			//}
            int index = 1;//notifierList..indexOf(this);
            builder.append("[").append(index).append("]");
            //}
        }
        else
        {
            if (builder.charAt(builder.length() - 1) != MetadataPath.MetadataPathSeparatorChar)
            {
                builder.append(MetadataPath.MetadataPathSeparator);
            }
            builder.append(this._memberName);
        }

        return builder.toString();
	}
	@Override
	 public boolean ChangeItemKey(V item, K newKey)
     {
         if (super.ContainsKey((K)newKey))
         {
             return false;
         }
         super.ChangeItemKey((V)item, (K)newKey);
         return true;
     }
}
